package com.mdnote.algorithm;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/9/6
 * @description 汉诺塔
 */
public class HanoiTower {

    public void move(int n, char a, char b, char c) {
         if (n == 1) {
            System.out.println("> 从 " +  a +  " 移动到 " + c);
        } else {
            // 移动只有三步：第一步是将N-1从A - B
            move(n - 1, b, a, c);
            // 将最下面那个从A - C
            System.out.println("> 从 " +  a +  " 移动到 " + c);
            // 最后把N - 1 从B到C
            move(n - 1, a, c, b);
        }
    }

    public static void main(String[] args) {
        HanoiTower hanoiTower = new HanoiTower();
        hanoiTower.move(2, 'A', 'B', 'C');
    }
}
